package com.gulimall.search.web;

import com.gulimall.search.service.SearchService;
import com.gulimall.search.vo.SearchParam;
import com.gulimall.search.vo.SearchResult;
import com.gulimall.search.vo.SkuInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.io.IOException;

/**
 * @author coder_ccy
 * @date 2022/3/23 11:25
 */

@Controller
public class IndexController {


    @Autowired
    private SearchService searchService;




    @GetMapping({"/","index.html"})
    public String index(SearchParam searchParam, Model model) throws IOException {


        SearchResult searchResult = searchService.search(searchParam);

        model.addAttribute("searchResult",searchResult);
        model.addAttribute("searchParam",searchParam);

        return "index";
    }


    @GetMapping("{skuId}.html")
    public String item(@PathVariable("skuId") long skuId,Model model){

        SkuInfo skuInfo = searchService.getSkuInfo(skuId);

        model.addAttribute("skuInfo",skuInfo);
        return "item";
    }
}
